package com.terrence.sso.token.client.web.server;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;

import com.terrence.sso.token.client.web.Config;

public final class SSOTokenVerifyProxy {
	
	private SSOTokenVerifyProxy(){};
	
	public static Boolean validTokenThroughSSOServer(String token){
		Boolean result = Boolean.FALSE;
   	 	PostMethod postMethod = new PostMethod(Config.SSO_SERVER_TOKEN);
   	 	postMethod.addParameter("token", token);
        HttpClient httpClient = new HttpClient();
        try {
            httpClient.executeMethod(postMethod);
            String isValid = postMethod.getResponseBodyAsString();
            postMethod.releaseConnection();
            result = "true".equals(isValid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
	}

}
